//
//  XSQMainTBController.m
//  BuDeJie
//
//  Created by Sem on 2018/6/25.
//  Copyright © 2018年 SEM. All rights reserved.
//

#import "XSQMainTBController.h"
#import "XSQEssenceViewController.h"
#import "XSQFollowViewController.h"
#import "XSQNewViewController.h"
#import "XSQMeViewController.h"
#import "XSQBaseNVC.h"
@interface XSQMainTBController ()
@property (nonatomic, weak) UIButton *plusButton;
@end

@implementation XSQMainTBController
+(void)initialize{
    //UIBarItem *item =[UIBarItem appearanceWhenContainedIn:self, nil];
    UITabBarItem *item =[UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:dic forState:UIControlStateNormal];
    
    NSMutableDictionary *dicH = [NSMutableDictionary dictionary];
    dicH[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:dicH forState:UIControlStateSelected];
    UITextField *f;
    
}
-(UIButton *)plusButton{
    if(_plusButton==nil){
        UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [btn sizeToFit];
        
        
        [self.tabBar addSubview:btn];
        _plusButton=btn;
    }
    return _plusButton;
}
- (void)viewDidLoad {
    [super viewDidLoad];
     //加载控制类
    [self addVC];
    //增加按钮
    [self addBarbtn];
    
    // Do any additional setup after loading the view.
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.plusButton.center = CGPointMake(self.tabBar.xmg_width/2, self.tabBar.xmg_height/2);
}
-(void)addVC{
    XSQEssenceViewController *eVC = [[XSQEssenceViewController alloc]init];
    XSQFollowViewController *fVC = [[XSQFollowViewController alloc]init];
    UIViewController *VC = [[UIViewController alloc]init];
    XSQNewViewController *nVC = [[XSQNewViewController alloc]init];
    UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"XSQMeViewController" bundle:nil];
    XSQMeViewController *mVC =[storyboard instantiateViewControllerWithIdentifier:@"XSQMeViewController"];
    NSArray *arr = @[eVC,nVC,VC,fVC,mVC];
    [self addVCWithArray:arr];
    
}
-(void)addVCWithArray:(NSArray<UIViewController *> *)arr{
    for (UIViewController *vc in arr) {
        XSQBaseNVC *nv = [[XSQBaseNVC alloc]initWithRootViewController:vc];
        [self addChildViewController:nv];
    }
}
-(void)addBarbtn{
    XSQBaseNVC *nv1 = self.childViewControllers[0];
    [nv1.tabBarItem setTitle:@"精华"];
    [nv1.tabBarItem setImage:[[UIImage imageNamed:@"tabBar_essence_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    [nv1.tabBarItem setSelectedImage:[[UIImage imageNamed:@"tabBar_essence_click_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    
    XSQBaseNVC *nv2 = self.childViewControllers[1];
    [nv2.tabBarItem setTitle:@"新帖"];
    [nv2.tabBarItem setImage:[[UIImage imageNamed:@"tabBar_new_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    [nv2.tabBarItem setSelectedImage:[[UIImage imageNamed:@"tabBar_new_click_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    
    
    XSQBaseNVC *nv4 = self.childViewControllers[3];
    [nv4.tabBarItem setTitle:@"关注"];
    [nv4.tabBarItem setImage:[[UIImage imageNamed:@"tabBar_friendTrends_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    [nv4.tabBarItem setSelectedImage:[[UIImage imageNamed:@"tabBar_friendTrends_click_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    
    XSQBaseNVC *nv5 = self.childViewControllers[4];
    [nv5.tabBarItem setTitle:@"我"];
    [nv5.tabBarItem setImage:[[UIImage imageNamed:@"tabBar_me_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    [nv5.tabBarItem setSelectedImage:[[UIImage imageNamed:@"tabBar_me_click_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
